class Solution {
public:
    TreeNode* buildTree(vector<int>& preorder, vector<int>& inorder) {
int m,i ;
if(inorder.size() == 0) 
{
return nullptr;
}
 m= preorder[0];
        TreeNode* n = new TreeNode(m);
        if(inorder.size() == 1) 
        {
            return n;
        }
        for(i = 0; i < inorder.size(); ++i){
            if(inorder[i] == m) break;
        }
        preorder.erase(preorder.begin());
        vector<int>leftinorder(inorder.begin(), inorder.begin()+i);
        vector<int>rightinorder(inorder.begin()+i+1, inorder.end());
        vector<int>leftpreorder(preorder.begin(), preorder.begin()+leftinorder.size());
        vector<int>rightpreorder(preorder.begin()+leftinorder.size(), preorder.end());
        n->left = buildTree(leftpreorder,leftinorder);
        n->right = buildTree(rightpreorder,rightinorder);
        return n;
    }
};